//
//  InspirationDetailPageVC.m
//  NewNest
//
//  Created by hesiyao on 16/1/23.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "InspirationDetailPageVC.h"
#import <AFNetworking.h>
#import <AFHTTPSessionManager.h>
@interface InspirationDetailPageVC ()
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) NSMutableDictionary *dataDic;
@end

@implementation InspirationDetailPageVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 创建视图
    [self createSubviews];
    
    //处理数据
    [self dataHandler];
    
}

/// 处理数据
- (void)dataHandler
{
    NSString *urlStr = [NSString stringWithFormat:@"http://ihome.cmfmobile.com:8080/sp/custom/getNewSpecialSingle.do?id=%@",self.idStr];
    [[AFHTTPSessionManager manager]GET:urlStr parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"灵感详情解析成功");
        NSMutableArray *arr = responseObject;
        self.dataDic = arr.firstObject;
        
        // 给titleLabel赋值 设置webview
        _titleLabel.text = _dataDic[@"title"];
        [_webView loadHTMLString:_dataDic[@"shareContent"] baseURL:nil];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"灵感详情解析失败");
    }];
}


/// 创建视图
- (void)createSubviews
{
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:_webView];
    [_webView release];
    _webView.scrollView.contentInset = UIEdgeInsetsMake(self.view.frame.size.height / 12, 0, 0, 0);
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, - self.view.frame.size.height / 10, self.view.frame.size.width, self.view.frame.size.height / 10)];
    [self.webView.scrollView addSubview: _titleLabel];
    _titleLabel.backgroundColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:19];
    [_titleLabel release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
